package com.cat.math;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/smallest-value-after-replacing-with-sum-of-prime-factors/description/
 * @create 2025/10/16 18:47
 * @since JDK17
 */

public class Solution13 {
    public int smallestValue(int n) {
        int sum = 0;
        while (true) {
            sum = 0;
            for (int i = 2; i * i <= n; i++) {
                while (n % i == 0) {
                    n /= i;
                    sum += i;
                }
            }
            if (n > 1) {
                sum += n;
            }
            if (sum == n) {
                return sum;
            }
            n = sum;
        }
    }
}
